<HTML>
<HEAD>

<TITLE>Contributing Changes with Command-Line CVS</TITLE>

</HEAD>
<BODY>
<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="3" BORDER="0" WIDTH="100%">
  <TR>
    <TD CLASS="Header" NOWRAP>Contributing changes with command-line CVS</TD>
  </TR>
</TABLE>

<TABLE BORDER="0" CELLSPACING="2" CELLPADDING="2" BORDER="0" WIDTH="100%">
  <TR>
<SPAN CLASS="PlainText">

<P>
<UL>
<DL>
<DT><A HREF="#work">Working with files</A>
<DT><A HREF="#filetypes">About file types</A>
<DT><A HREF="#contributing">Contributing your changes</A>
	<DD><A HREF="#cvscommit">Committing files and directories</A>
	<DD><A HREF="#cvsadd">Adding new files and directories</A>
<DT><A HREF="#cvsimport">Importing existing source files</A>
<DT><A HREF="#cvsandrcs">CVS and RCS</A>
<DT><A HREF="#keywords">Using keywords</A>
<DT><A HREF="#cvsupdate">Keeping your working copy up to date (cvs update)</A>
<DT><A HREF="#cvstatus">Comparing your working files to the CVS repository</A>
<DT><A HREF="#otherdiff">Comparing files before you commit</A>
<DT><A HREF="#cvsmerging">Merging your changes</A>
<DT><A HREF="#cvsresolving">Resolving merge conflicts</A>
<DT><A HREF="#reverting">Revision history and reverting</A>
</DL>
</UL>

<P>
<SPAN CLASS="InputHeader"><A NAME="work"></A>Working with files</SPAN>
<P>
Between checking files out of the project repository and checking them back in, CVS has virtually nothing to do with how files are used in the project environment or build process. That is governed by the project owner and other external factors unique to the project.
<P>
When you make changes to existing files, you must edit your working copies of these files in a file editor on your local machine using your file editor of choice. None of the changes you make to your working files has any effect on the project's source repository or on other developers' work until you check in (that is, do a <I>cvs commit</I>) your modified versions of files.
<P>
More about "<A HREF="http://www.cvshome.org/docs/manual/cvs_1.html#SEC1" TARGET=_NEW>What CVS is not</A>."
More about <A HREF="http://cvshome.org/docs/manual/cvs_14.html#SEC111" target="_new">How your project builds interact with CVS</A>
<P>
<BR>
<BR>

<SPAN CLASS="InputHeader"><A NAME="filetypes"></A>About file types</SPAN>
<P>
<P>
The information provided in this document about CVS commands and actions assumes that the project files you are working with are text files. It is possible to include binary files in version control with CVS, although there are some special issues.
<P>
More about <A HREF="http://cvshome.org/docs/manual/cvs_9.html#SEC80" TARGET="_new">Handling binary files</A> in CVS.
<P>
<BR>
<BR>

<SPAN CLASS="InputHeader"><A NAME="contributing"></A>Contributing your changes into CVS</SPAN>
<UL>
<P><A NAME="cvscommit"></A><LI>To <I>commit</I> your changes to a file into the shared repository, type:
<BLOCKQUOTE>
       <B>cvs commit -m "Type your changes message here" FILENAME</B>
</BLOCKQUOTE>
<P>
If you do not include a description of your change to the file, you will be prompted to add it by invoking your file editor before CVS can complete the commit action. 
<P><LI>To commit your changes to all files in a directory and any subdirectories:
<BLOCKQUOTE>
          <B>cd top_directory_to_commit</B><BR>
          <B>cvs commit -m "Type your change message here"</B>
</BLOCKQUOTE>
</UL>
<P>
All commits are logged automatically and posted to the project's cvs mailing list.
<P>

<A NAME="cvsadd"></A><SPAN CLASS="InputHeader">Adding files/directories</SPAN>

        <P>To <I>add</I> a new file to the CVS repository after you have first created and edited it in your working directory, type:
<BLOCKQUOTE>
          <B>cvs add filename</B><BR>
</BLOCKQUOTE>
         Then follow up with the &quotcvs commit filename&quot command. If you do not first add the file, CVS does not recognize it.</LI>

<P>
If you have cvs write permissions, you can add subdirectories to your project's source tree using the &quot<B>cvs add</B>&quot command. You can then move existing files into new subdirectories with the &quot;<B>cvs move</B>&quot; command.
<P>
<A HREF="http://cvsbook.red-bean.com/cvsbook.html#Committing" TARGET="_new">More about committing changes</A><BR>
<A HREF="http://cvshome.org/docs/manual/cvs_7.html#SEC66" TARGET="_new">More about adding files and directories</A>
<P>
<BR>
<BR>

<A NAME="cvsimport"></A> <B>Importing existing code?</B>
<P>
If you have existing files to add to the project, you can import these into CVS using the following command:
<BLOCKQUOTE>
		<B>cvs import filename</B>
</BLOCKQUOTE>

<P>
Importing allows you to add a lot of files at once, something like a super "cvs add." To import <I>all</I> existing directories and files, in your top level directory type:
<P>
<B>cvs import -m &quotlog message&quot projectname</B>
<P>
This creates the files and directories in the CVS repository for your project on this site. If you want to preserve these files and directories in their original state, you may want to tag or archive this set of original files before you or any other developers begin checking out working copies of project files.
<P>
If your existing files are already under versioning control -- either in another CVS repository or in a versioning different system such as RCS -- there is no automated method for importing existing files that retains file histories. Using the cvs import command, copying files over, or creating them as new files does not retain these histories.
<P>
<BR>
<BR>

<A NAME="copyfromrcs"></A>Neither cvs import nor cvs copy preserves  the RCS revision histories of existing files brought in to CVS, but there is a way to do this by using:
<BLOCKQUOTE>
<B>cvs cp filename,v</B>
</BLOCKQUOTE>
If you do not copy files using the "filename,v", all versioning information for each file is lost.
<P>
<A HREF="http://www.gnu.org/manual/cvs/html_chapter/cvs_20.html#SEC112" TARGET="_new">More about &quot;<B>cvs import&quot</B></A>
<P>
<BR>
<BR>

<SPAN CLASS="InputHeader"><A NAME="cvsandrcs"></A>CVS and RCS</SPAN>
<P>
If you're already familiar with RCS, both RCS and CVS use a similar format for storing the version control histories of individual files. But you should be aware of at least two critical differences in adapting CVS:
<P>
<UL>
<LI>One of the central principals in RCS is file locking, which prevents other developers from checking out or modifying a file when you have checked it out. The benefit to file locking is that developers never have to deal with conflicting modifications within files. RCS protects files by only allowing them to be modified by one person at a time. Therefore, the drawback to RCS is: you can't commit your changes to a file while another developer has it checked out.
<LI>The central tenant of CVS is to allow developers to check out, modify, and commit files concurrently, truly a benefit to projects with remote, geographically dispersed developers. The tradeoff is that on a CVS version controlled project, you can count on dealing with merge conflicts in files. The only method for resolving such conflicts is by hand-editing the file. Thus, project workflow with CVS ends up being a little different.
</UL>
<P>

<A HREF="http://www.cvshome.org/cyclic/cyclic-pages/rcs.html" TARGET="_new">More about RCS and CVS</A>
<P>
<BR>
<BR>

<A NAME="keywords"></A><SPAN CLASS="InputHeader">Keyword substitution</SPAN>
<P>
Keyword substitution (a.k.a keyword expansion) is an RCS holdover that may be useful to you as a developer. Keywords essentially let you embed version information permanently in source files. A string containing the full version information associated with a particular keyword is substituted whenever the file is subsequently revised. 
<P>
As an example, including:
<BLOCKQUOTE>
<B>$Author: templedf $</B>
</BLOCKQUOTE>
within the files permanently retains the login name of the user who checked in that revision.
<P>Keyword substitution is a method for tracking file versions once the files are no longer part of a CVS repository. Keyword substitution can also be configured and suppressed.
<P>
<A HREF="http://cvshome.org/docs/manual/cvs_12.html#SEC98" TARGET="_new">More about keywords (including a list of common keywords)</A>
<P>
<BR>
<BR>

<A NAME="cvsupdate"></A><SPAN CLASS="InputHeader">Keeping your working files up to date with the repository</SPAN>
<P>
If you want to look before you leap, you can get a list of all files in your local directory not up to date with the project repository by using the following command:<BR>
<BLOCKQUOTE>
          <B>cvs -qn update</B> </LI>
</BLOCKQUOTE>
Files in the affected directory or directories are listed with their current status indicated as follows:
<UL>
<LI>? = File is unrecognized by CVS (needs to be added and committed).
<LI>A = File is added; file is recognized by CVS but still needs to be committed to the repository.
<LI>M = File has been modified by another developer since you checked out your working copy. This means that you need to update.
<LI>U = File is updated.
<LI>C = File has merge conflicts that must be resolved by hand.
</UL>
<P>
To go ahead and actually perform an update to make your working directory up to sync with the repository, the command is:
<BLOCKQUOTE>
	<B>cvs update</B>
</BLOCKQUOTE>
You can also update individual files by adding the filename to the command.
<P>Or, to include any new directories when updating, do:
<BLOCKQUOTE>
        <B>cvs update -d</B> 
</BLOCKQUOTE>
<P> 
<A HREF="http://www.gnu.org/manual/cvs/html_chapter/cvs_20.html#SEC132" TARGET="_new">More about the cvs update command</A><BR>
<A HREF="http://www.gnu.org/manual/cvs/html_chapter/cvs_20.html#SEC134" TARGET="_new">More about CVS update output</A>
<P>
<BR>
<BR>

<A NAME="cvstatus"></A><SPAN CLASS="InputHeader">Comparing your working files to the repository</SPAN>
<P>
Another way to determine whether all of your working files are in sync with the latest versions in the repository is with the command:
<BLOCKQUOTE>
<B>cvstatus</B><BR>
</BLOCKQUOTE>
or for status on individual files:<BR> 
<BLOCKQUOTE>
<B>cvs status filename</B>
</BLOCKQUOTE>
<P>
This comparison may return one of the following messages:
<P>
<DL>
<DT><B><I>Locally modified</I></B> <DD>Your version has not yet been committed.
<DT><B><I>Needs patch</I></B> <DD>Your version needs to be updated because someone else has made changes.
<DT><B><I>File had conflicts on merge</I></B> <DD>CVS could not resolve changes made to this file and committed. (<A HREF="cvsresolving">Resolving merge conflicts</A>.)
</DL>

<P>
In general, a good rule of thumb is to make sure your working files are up to date with the repository <I>just before you commit your changes to a file</I>. The reason for this is that sometimes your commit may be unsuccessful, for example, you may be trying to commit from the wrong directory or perhaps another developer has committed changes to that same file after you checked it out of the repository or last updated it. Trying to commit your changes to an older version of the same file often causes conflicts when CVS tries to merge these. The result of your commit attempt under such circumstances is a somewhat daunting failure message about "dying gasps" from CVS. (Unfortunately, you don't find this out until <I>after</I> you've gone through the process of mentally composing and entering a pithy change log message.)
<P>
<P><LI>To see the differences between your copy of a file and the latest version in the repository:<BR>
<BLOCKQUOTE>
          <B>cvs diff filename</B> </LI>
</BLOCKQUOTE>
<P>
<A HREF="http://cvsbook.red-bean.com/cvsbook.html#Finding_Out_What_You__And_Others__Did_--_update_And_diff" TARGET=_NEW>More about comparing your work with the project repository</A>
<P>
<BR>
<BR>

<A NAME="diffs"></A><SPAN CLASS="InputHeader">Comparing versions of files <I>before</I> you commit (diff)</SPAN>
<P>
Perhaps you want to see the changes another developer has made to the same file <I>before</I> you commit your own changes. For example, suppose you are committing some very complex changes which you anticipate may conflict with another developer's work.
<P>
In this case, a workable solution is to save off your working file under a different name (something like: "filename-new"). Then you can run the &quot<B>cvs update</B>&quot command and compare the latest version from the repository with your file before committing your changes. You can even compare the two files side-by-side using the following diff command:
<BLOCKQUOTE>
<B>diff -y filename filename-new</B>
</BLOCKQUOTE>
<P>
<BR>
<BR>

<A NAME="cvsmerging"></A><SPAN CLASS="InputHeader">Merging your changes with other developers' changes</SPAN>
<P>
By giving the &quot<B>cvs update</B>&quot command, you are essentially telling CVS to merge the latest versions of files from the repository into your working copies.
<P>
Sometimes, however, other modifications made to a file since you last updated do not mesh well with your version. Or, you've made changes that conflict with the repository version. CVS makes every attempt to resolve such conflicts automatically when you update and commit, but sometimes it cannot resolve everything. Conflicts within the file must be resolved by hand.
<P>
<BR>
<BR>

<A NAME="cvsresolving"></A><LI>Resolving merge conflicts
<P>
To resolve merge conflicts, open the file in your file editor. Look for lines or sections marked by &quot>>>>>>&quot and &quot<<<<<<<&quot. When CVS cannot resolve a conflict, it includes both versions of the affect line or sections in the file, usually the latest version first. Your task is to delete the unwanted lines, along with the lines containing the conflict symbols and revision numbers. Then save the file and commit.
<P>
<A HREF="http://www.gnu.org/manual/cvs/html_chapter/cvs_7.html#SEC40" TARGET="_new">An example of a conflict</A><BR>
<A HREF="http://cvsbook.red-bean.com/cvsbook.html#Detecting_And_Resolving_Conflicts" TARGET="_new">More about resolving conflicts</A>
<P>
<BR>
<BR>

<A NAME="reverting"></A><SPAN CLASS="InputHeader">Revision history and reverting</SPAN>
<P>
Beyond the usefulness of being able to review a file's modification history using the &quot<B>cvs log</B>&quot command to review, earlier versions can actually be restored as the most current revision (that is, to the "repository head") by the process of <I>reverting</I>. This can become a particularly useful option if you want or need to return to an earlier point in a file's evolution for whatever reason, somewhat like being able to turn back the clock.  
<P>
The command to revert to an earlier version of a file is:
<BLOCKQUOTE>
<B>cvs up -r filename version_#</B>
</BLOCKQUOTE>
<P>
Reverting may results in "sticky tag" errors. You can resolve these using the following update command with a special switch: 
<BLOCKQUOTE>
<B>cvs update -dAP</B>
</BLOCKQUOTE>
(<A H REF="http://cvsbook.red-bean.com/cvsbook.html#Getting_Snapshots__Dates_And_Tagging_" TARGET="_new">What are sticky tag errors?</A>)


<!--
revisions are specific updates to files, i.e. 1.1, 1.2, 1.3
versions are SETS of file revisions tagged and named at a certain point in time (the confusion comes because versions are sometimes named 1.0, 1.1, 1.2 etc. but don't have to be named that way, can be any set of characters project owner designates)

-->
<P>
<BR>
<BR>

<A HREF="http://www.gnu.org/manual/cvs/html_chapter/cvs_16.html#SEC72" TARGET="_new">More about revision history</A><BR>
<A HREF="http://cvsbook.red-bean.com/cvsbook.html#Examining_And_Reverting_Changes" TARGET="_new">More about reverting</A>



<!--
<P>
<A NAME="cvstips"><span class="InputHeader">Feedback on this document</span></A>
<P>
The author of this help document has made every attempt to compile accurate, helpful information about using CVS for projects hosted on this site. If you think any content in the above document is wrong, inadequate, or something is just plain missing ... that's good. This is open source, so step up to the plate and contribute your suggestions for additions and improvements.
<P>
-->

<HR NOSHADE SIZE=1>
<A HREF="Help.html">Back to main Help index</A></P></SPAN>

</SPAN> 
</TR>
</TABLE>
</BODY>
</HTML>
